// Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
  pub val: i32,
  pub left: Option<Rc<RefCell<TreeNode>>>,
  pub right: Option<Rc<RefCell<TreeNode>>>,
}

impl TreeNode {
  #[inline]
  pub fn new(val: i32) -> Self {
    TreeNode {
      val,
      left: None,
      right: None
    }
  }
}
use std::{rc::Rc};
use std::cell::RefCell;

struct Solution {}

impl Solution {
    pub fn is_same_tree(p: Option<Rc<RefCell<TreeNode>>>, q: Option<Rc<RefCell<TreeNode>>>) -> bool {
      match (p, q) {
        (Some(n1), Some(n2)) => {
          let t1 = n1.borrow();
          let t2 = n2.borrow();
          if  t1.val != t2.val {
            return false;
          }
          let l = Rc::new(&t1.left);
          
          Solution::is_same_tree( t1.left.clone(), t2.left.clone()) && Solution::is_same_tree(t1.right.clone(), t2.right.clone()) 
        },
        (None, None) => true,
        _ => false,
      }
    }
}